use crate::dto;
use crate::mq;
use std::sync::Arc;

pub struct Client {
    client: Arc<mq::client::Client>,
}

impl Client {
    pub fn new(client: Arc<mq::client::Client>) -> Self {
        Self { client }
    }

    pub async fn publish_setup_event(
        &self,
        node_id: &str,
        payload: dto::event::endpoint::peer::wireguard_config::SetupEventPayload,
    ) -> Result<(), anyhow::Error> {
        let event = dto::event::endpoint::peer::wireguard_config::new_setup_event(payload);

        self.client
            .publish_json(mq::client::node::topic(node_id), &event)
            .await
    }
}
